package com.example.common.utils;

import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.concurrent.TimeUnit;

public class SimpliRedisLock implements ILock{
    private StringRedisTemplate stringRedisTemplate;
    private String name;
    private static final String KEY_PREFIX = "lock:";


    public SimpliRedisLock(StringRedisTemplate stringRedisTemplate, String name) {
        this.stringRedisTemplate = stringRedisTemplate;
        this.name = name;
    }
    @Override
    public boolean tryLock(long timeoutSec) {
        stringRedisTemplate.opsForValue().setIfAbsent(KEY_PREFIX + name, "1", timeoutSec, TimeUnit.SECONDS);
        return false;
    }

    @Override
    public void unlock() {

    }
}
